<template>
  <section class="component robbery-components">
    <el-form :model="modifyModel" :rules="rules" ref="modify-form" label-width="90px" class="tableInput">
      <el-form-item label="申请说明" prop="contents">
        <el-input type="textarea" v-model="modifyModel.applyDescription" :maxlength="500" show-word-limit></el-input>
      </el-form-item>
    </el-form>
    <div class="operate-buttons">
      <el-button @click="close">取消</el-button>
      <el-button @click="commit">提交</el-button>
    </div>
  </section>
</template>

<script lang="ts">
import Vue from "vue";
import Component from "vue-class-component";
import { Dependencies } from "~/core/decorator";
import { State, Action, Getter } from "vuex-class";
import { PrincipalService } from "~/services/domain-service/principal.service";
import { Emit, Prop, Watch } from "vue-property-decorator";
import { Form } from "element-ui";
import { CaseApplyRecordService } from '~/services/domain-service/case-apply-record.service.ts';

@Component({
  components: {}
})
export default class RobberyComponents extends Vue {
  @Prop()
  private caseIds: any;

  @Dependencies(CaseApplyRecordService) private caseApplyRecordService: CaseApplyRecordService;
  //委托方数据实体
  private modifyModel: any = {
    applyDescription: "", // 申请说明
    applyCategory: "GRAB_CACE",
    caseIds: this.caseIds,
    confirm: 0
  };
  //数据校验
  private rules: any = {
    applyDescription: [{ required: true, message: "请输入申请说明", trigger: "blur" }],
  };
  @Emit("refreshList")
  public refreshList() { }
  @Emit("close")
  public close() {
    this.reset();
  }

  //重置方法
  private reset() {
    const modifyForm: any = this.$refs["modify-form"];
    modifyForm.resetFields();
  }
  /**
   * 首次打开调用
   */
  private update() {

  }


  /**
   * 提交验证并并与数据库交互
   */
  private commit() {
    const modifyForm: any = this.$refs["modify-form"];
    modifyForm.validate(valid => {
      if (!valid) return false;
      this.caseApplyRecordService.applyRobCase(this.modifyModel)
        .subscribe((data) => {
          this.$message.success('抢案申请成功');
          this.close()
        });
    });
  }




}
</script>

<style lang="less" scoped>
</style>
